const App = {
    mixins: [Query],//配置文件，路径/utils/mixins.js
    data() {
        return {
            photo,
            page: {
                activeName: 'first',
                value1: '',
                PageNumber: 1, //页码
                RowAmount: 10,
                Condition: window.btoa(unescape(encodeURIComponent("%%")))
            },
            str1: '',
            str: '',
        }
    },
    mounted() {

    },
    methods: {
        Treedata() {
            const _this = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/clientOperation/getDistrictTree`,
                type: "GET",
                data: {
                    DistrictCode: '232723'

                },
                success: (data) => {
                    this.treeData = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        },
        handleNodeClick(data, node) {
            this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + data.ProvinceNumber + "%,%" + this.page.value1 + "%")))
            this.postgetList(this.page);
        },
        check() {
            this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%")))
            this.postgetList(this.page);
        },
        handleEdit(row){
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/queryMultiTableByCondition`,
                method: "post",
                data: {
                    Data: JSON.stringify([{
                        tableName: 'article_inventory',
                        Condition: window.btoa(unescape(encodeURIComponent("Article_Inventory_SerialNumber IN (" + Article_Inventory_SerialNumber + ")"))),
                    }, {
                        tableName: 'personal_points_account',
                        Condition: window.btoa(unescape(encodeURIComponent("ID_Card_Number='" + this.account.ID_Card_Number + "'"))),
                    }]),
                },
                success: ({ article_inventory, personal_points_account }) => {
                    const ls_Datetime = getYMDHMSDate();
                    let sales_order_detail = [], article_inventory_out = [], personal_points_change_log = [];
                    //生成销售订单明细和出库单
                    this.multipleSelection.forEach(item => {
                        sales_order_detail.push({
                            Article_Inventory_SerialNumber: item.Article_Inventory_SerialNumber,
                            Article_SerialNumber: item.Article_SerialNumber,
                            Specifications_SerialNumber: item.Specifications_SerialNumber,
                            Quantity: item.Quantity,
                            Unit_Points: item.Points_Type == '0' ? item.Villager_Point : item.Party_Point,
                            Points_Type: item.Points_Type,
                            Sales_Points: accMul((item.Points_Type == '0' ? item.Villager_Point : item.Party_Point), item.Quantity)
                        })
                        article_inventory_out.push({
                            Article_Inventory_SerialNumber: item.Article_Inventory_SerialNumber,
                            Article_SerialNumber: item.Article_SerialNumber,
                            Specifications_SerialNumber: item.Specifications_SerialNumber,
                            Inventory_Out_Datetime: ls_Datetime,
                            Children: {
                                article_inventory_out_detail: [{
                                    Article_Purpose: '商品被兑换',
                                    Inventory_Out_Quantity: item.Quantity
                                }]
                            }
                        })
                    })
                    //回写积分账户
                    personal_points_account.forEach(item => {
                        if (item.Points_Type == '0') {
                            item.Remain_Points = accSub(item.Remain_Points, this.selectArticle.Villager_Point);
                            item.Sales_Points = accAdd(item.Sales_Points, this.selectArticle.Villager_Point);
                        } else if (item.Points_Type == '1') {
                            item.Remain_Points = accSub(item.Remain_Points, this.selectArticle.Party_Point);
                            item.Sales_Points = accAdd(item.Sales_Points, this.selectArticle.Party_Point);
                        }
                    });
                    //生成日志
                    if (this.selectArticle.Villager_Point > 0) {
                        personal_points_change_log.push({
                            ID_Card_Number: this.account.ID_Card_Number,
                            Points_Title: '兑换商品扣减村民积分',
                            Points_Type: '0',
                            Change_Points: '-' + this.selectArticle.Villager_Point,
                            Remain_Points: this.remainPoints.New_Villager_Remain_Points,
                            Notes: '兑换商品扣减村民积分'
                        })
                    }
                    if (this.selectArticle.Party_Point > 0) {
                        personal_points_change_log.push({
                            ID_Card_Number: this.account.ID_Card_Number,
                            Points_Title: '兑换商品扣减党员积分',
                            Points_Type: '1',
                            Change_Points: '-' + this.selectArticle.Party_Point,
                            Remain_Points: this.remainPoints.New_Party_Remain_Points,
                            Notes: '兑换商品扣减党员积分'
                        })
                    }
                    //回写商品库存
                    article_inventory.forEach(item => {
                        let obj = this.multipleSelection.filter(i => i.Article_Inventory_SerialNumber == item.Article_Inventory_SerialNumber)[0];
                        item.Inventory_Quantity = accSub(item.Inventory_Quantity, obj.Quantity);
                        item.Inventory_Out_Quantity = accAdd(item.Inventory_Out_Quantity, obj.Quantity);
                    })
                    let lJSONObject_DataSet = {
                        Add: {
                            sales_order: [{//销售订单
                                ID_Card_Number: this.account.ID_Card_Number,
                                Sales_Datetime: ls_Datetime,
                                Sales_Villager_Point: this.selectArticle.Villager_Point,
                                Sales_Party_Point: this.selectArticle.Party_Point,
                                Children: {
                                    sales_order_detail
                                }
                            }],
                            article_inventory_out,//出库单
                            personal_points_change_log,//日志
                        },
                        Modify: {
                            personal_points_account,//回写积分账户
                            article_inventory,//回写库存
                        }
                    };
                    let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
                    lJSONObject_DataSet['Add']['base_operation_log'] = [{
                        Operation_Type: '0',
                        Operation_Path: this.relativePath,
                        Operation_Main,
                        Operation_Interface: "generalSaveByRequestBody",
                        Operation_IP: getIpAddress()
                    }]
                    submitSave(lJSONObject_DataSet, (res) => {
                        if (res.Status == 'success') {
                            this.getList(this.form);
                            this.showDialog = false;
                            this.account = {};
                            this.searchQuery = '';
                            this.$message({
                                message: '结算成功',
                                type: 'success'
                            });
                        }
                        this.loading = false;
                    })
                    // $.ajax({
                    //     headers: requestHeaders("JSON"),
                    //     url: `${mh}/generalBusiness/generalSaveByRequestBody`,
                    //     method: "post",
                    //     data: JSON.stringify({
                    //         Data: lJSONObject_DataSet,
                    //     }),
                    //     success: (res) => {
                    //         if (res.Status == 'success') {
                    //             this.getList(this.form);
                    //             this.showDialog = false;
                    //             this.account = {};
                    //             this.searchQuery = '';
                    //             this.$message({
                    //                 message: '结算成功',
                    //                 type: 'success'
                    //             });
                    //         }
                    //     },
                    //     complete: (XMLHttpRequest) => {
                    //         this.loading = false;
                    //         requestPretreatment(XMLHttpRequest)
                    //     }
                    // });
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                }
            })
        }
    },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
